package com.zf.shuashua.utils;

import android.animation.ValueAnimator;
import java.lang.reflect.Field;


public class ValueAnimatorUtil {

	/**
	 * 如果动画被禁用，则重置动画缩放时长
	 */
	public static void resetDurationScaleIfDisable() {
		if (getDurationScale() == 0)
			resetDurationScale();
	}

	/**
	 * 重置动画缩放时长
	 */
	public static void resetDurationScale() {
		try {
			getField().setFloat(null, 1);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static float getDurationScale() {
		try {
			return getField().getFloat(null);
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	private static Field getField() throws NoSuchFieldException {
		Field field = ValueAnimator.class.getDeclaredField("sDurationScale");
		field.setAccessible(true);
		return field;
	}

}
